package com.lv.suyiyong.hfr.adapter

import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.service.bean.BrandItemBean
import com.lv.service.bean.GoodsItemBean
import com.lv.suyiyong.hfr.R
import com.lv.suyiyong.hfr.databinding.ItemHotSalerHeaderBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class HotSalerParentAdapter(private val datas: MutableList<BrandItemBean>?) :
    BaseQuickAdapter<BrandItemBean, DataBindBaseViewHolder>(
        R.layout.item_hot_saler_header, datas
    ) {
//    override fun convert(
//        holder: DataBindBaseViewHolder,
//        item: TelSecondCategory,
//        payloads: List<Any>
//    ) {
//        super.convert(holder, item, payloads)
//        val mBinding: ItemCardCategoryImageBottomBinding =
//            holder.getBind() as ItemCardCategoryImageBottomBinding
//        mBinding.ivImageTag.visibility = if (item.isSelcted) View.VISIBLE else View.GONE
//
//    }

    override fun convert(holder: DataBindBaseViewHolder, item: BrandItemBean) {
        val mBinding: ItemHotSalerHeaderBinding =
            holder.getBind() as ItemHotSalerHeaderBinding
//        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        val spuList = item.spuList
        val mSpus = mutableListOf<GoodsItemBean>()
        spuList?.let { mSpus.addAll(it) }
        mBinding.tvName.text = item.name
        val gridLayoutManager = object : GridLayoutManager(context, 3) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        mBinding.rvChild.layoutManager = gridLayoutManager
        val mAdapter = HotSalerChildAdapter(mSpus)
        mBinding.rvChild.adapter = mAdapter

        mBinding.llCategory.setOnClickListener {
            onViewItemClickListener?.onClick(layoutPosition, item)
        }

    }

    var onViewItemClickListener: OnPositionTListener<BrandItemBean>? = null


}